  // 初始化
  let playpause_btn = document.querySelector(".play");
  let start_time = document.querySelector(".start-time");
  let end_time = document.querySelector(".end-time");
  let seek_input = document.querySelector(".seek-input");
  let stripBox = document.querySelector(".strip-box");
  let posterBox = document.querySelector(".poster-box");



  let audio = document.createElement("audio"); //生成一个audio元素
  let isPlayer = false;
  let updateSeekTimer;

  // 加载音乐
  function onLoadMusic() {
    audio.src =
      "http://tyst.migu.cn/public/product23/2018/11/15/2017年07月24日11点47分内容准入华纳11首/歌曲下载/MP3_40_16_Stero/6005759Z0MB.mp3";
    audio.load();
    updateSeekTimer = setInterval(seekUpdate, 1000);
  }

  // 播放|暂停
  function onPlayAndPause() {
    if (isPlayer == false) {
      audio.play();
      isPlayer = true;
      playpause_btn.innerHTML = '<span class="icon-pause"></span>';
      $(stripBox).addClass("active");
      $(posterBox).removeClass("pause");
    } else {
      audio.pause();
      isPlayer = false;
      playpause_btn.innerHTML = '<span class="icon-play2"></span>';
      $(stripBox).removeClass("active");
      $(posterBox).addClass("pause");
    }
  }
  // 计算时间，进度
  function seekUpdate() {
    let seekPosition = 0;
    if (!isNaN(audio.duration) && isPlayer) {
 
      seekPosition = (audio.currentTime / audio.duration) * 100;
      seek_input.value = seekPosition;

      // Math.floor() 返回小于或等于一个给定数字的最大整数
      let currentMinutes = Math.floor(audio.currentTime / 60);
      let currentSeconds = Math.floor(audio.currentTime - currentMinutes * 60); //秒不能超过60，所以要当前总秒数 减去 分钟的总秒数 得到 剩下秒数

      if(currentMinutes < 10) currentMinutes = "0"+currentMinutes
      if(currentSeconds < 10) currentSeconds = "0"+currentSeconds
      start_time.textContent = currentMinutes+":"+currentSeconds;

      let durationMinutes = Math.floor(audio.duration / 60);
      let durationSeconds = Math.floor(audio.duration - durationMinutes * 60);

      if (durationSeconds < 10) { durationSeconds = "0" + durationSeconds; }
      if (durationMinutes < 10) { durationMinutes = "0" + durationMinutes; }
      end_time.textContent = durationMinutes + ":" + durationSeconds;
    }
  }

  // 拖动滑块
  function seekTo(){
    audio.currentTime = seek_input.value/100 * audio.duration
  }

  onLoadMusic();